package com.test.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * 操作类型
 *
 * @author sangkuofeng
 * @date 2023/11/12 01:43
 */
public enum ActionType {
    SUBSCRIBE("subscribe"),
    READ("read"),
    READ_STRING("readString"),
    WRITE_STRING("writeString"),
    BEEP("beep"),
    WRITE_CARD_NUMBER("writeCardNumber"),
    READ_CARD_NUMBER("readCardNumber"),
    ;

    private String code;

    ActionType(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public static ActionType getTypeByCode(String code) {
        Optional<ActionType> optional = Arrays.stream(ActionType.values()).filter(item -> StringUtils.equals(code, item.getCode())).findFirst();
        return optional.isPresent() ? optional.get() : null;
    }

}
